<template>
	<div>
		<!-- <div v-if="status && updateData.length==0" class="m-t-30">
			<a-empty description="无更新" />
		</div>

		<template v-else>
			<a-result :title="updateData?.version_name" :sub-title="updateData?.content">
				<template #icon>
					<CloudDownloadOutlined />
				</template>
				<template #extra>
					<div v-if="updateData?.pwd" class="m-b-20 grey">提取密码：{{updateData?.pwd}}</div>
					<div>
						<a :href="updateData?.url" target="_blank" class="m-r-20">
							<a-button key="console" type="primary">立即下载</a-button>
						</a>
						<a :href="updateData?.download_url" target="_blank">
							<a-button key="buy">下载其他版本</a-button>
						</a>
					</div>
				</template>
			</a-result>
		</template> -->

		<div class="m-b-40 flex flex-jc-sb">

			<div>
				<div class="flex flex-jc-sb">
					<div>
						<a-button type="primary" ghost>当前系统为：翼鸟V2平台版</a-button>
					</div>
					<div>
						<!-- <a-button type="primary" loading>更新服务端</a-button> -->
						<!-- <a-button type="primary" loading>
							<template #icon>
								<CloudDownloadOutlined />
							</template>
							更新服务端
						</a-button> -->
					</div>
				</div>


				<h3 class="font-b m-t-30">V2版本前端代码/服务端代码仓库地址</h3>
				<a href="https://gitee.com/cendxia/netss_v2" target="_blank">https://gitee.com/cendxia/netss_v2</a>
				<p>分支说明：master（前端代码）；service（服务端）</p>

				<h3 class="font-b m-t-30">管理后台仓库地址</h3>
				<a href="https://gitee.com/cendxia/netss-admin"
					target="_blank">https://gitee.com/cendxia/netss-admin</a>
				<p>分支说明：master（平台版）；basice（非平台版）</p>

				<h3 class="font-b m-t-30">创作中心下载地址</h3>
				<a href="https://wwgr.lanzouy.com/b00ocyztub" target="_blank">https://wwgr.lanzouu.com/b00odei0wd
					密码:fgpt</a>
			</div>

			<div class="m-l-20 box-shadow-d br-10 padding-30" style="max-width: 550px;">
	
				<div class="flex flex-ai-c flex-jc-sb">
					<div class="flex1 m-r-20">
						<a-alert v-if="updateErorr && updateErorrText" :message="updateErorrText" type="error" show-icon />
					</div>
					
					<div>
						<template v-if="checkUpdates===false || checkUpdates===true">
							<a-button type="primary" size="large" v-if="checkUpdates===false" @click="getNewVersion">
								<template #icon>
									<CloudSyncOutlined />
								</template>
								检查更新
							</a-button>
							<a-button type="primary" size="large" v-if="checkUpdates===true" loading>
								<template #icon>
									<LoadingOutlined />
								</template>
								检查更新
							</a-button>
						</template>
						
						
						<a-button type="primary" size="large" disabled v-if="latest">
							<template #icon>
								<CheckCircleOutlined />
							</template>
							已是最新版
						</a-button>
						
						<a-button type="primary" size="large" v-if="serviceUpdateData.update_url && !updating" @click="systemUpdate">
							<template #icon>
								<CloudDownloadOutlined />
							</template>
							更新服务端
						</a-button>
						
						<a-button type="primary" size="large" loading v-else-if="updating">
							<template #icon>
								<CloudDownloadOutlined />
							</template>
							更新中……
						</a-button>
						
						<a-button type="primary" danger size="large" v-if="updateErorr">
							<template #icon>
								<CloseCircleOutlined />
							</template>
							更新失败
						</a-button>
						
						<a-button type="primary" size="large" style="background-color: #009900;" v-if="updateSuccess">
							<template #icon>
								<CheckCircleOutlined />
							</template>
							更新成功
						</a-button>
					</div>
				</div>
				
				<div class="m-t-30">
					<div class="font-18 font-b" v-if="serviceUpdateData.describe">本次更新内容</div>
					<div class="color-3 m-t-20" v-if="serviceUpdateData.describe">{{serviceUpdateData.describe}}</div>
					
					<div class="font-18 font-b m-t-40">注意：</div>
					<div class="color-6 m-t-10">本次更新仅更新服务端API代码和数据库，更新新请<b>务必</b>做好代码和数据库的备份。以免更新失败造成系统无法正常运行；其他前端代码的更新请自行手动下载更新。</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import apiService from '../../api/apiService.js'

	export default {
		data() {
			return {
				status: false,
				updateData: [],
				
				versionNumber: '' ,// 当前版本号
				
				checkUpdates: false, //是否检测更新
				thereUpdate: false, // 是否有更新,
				updateErorr: false, // 更新失败
				updateErorrText: '', // 更新失败提示
				updateSuccess: false, // 更新成功
				updating: false, // 更新中
				latest: false, // 最新
				
				serviceUpdateData: {
					version: '',
					version_number: '',
					describe: '',
					update_url: ''
				},
				
				
			}
		},
		mounted() {
			// this.getSystemVersion() // 未使用
		},
		methods: {
			
			
			// 获取新版信息
			getNewVersion(){
				this.checkUpdates = true
				apiService.getNewVersion().then(res => {
					if (res.status == 1) {
						if(res.result.update_url){
							this.serviceUpdateData = res.result
							this.thereUpdate = true
						}else{
							this.latest = true
						}
						this.checkUpdates = 'ok'
					}else{
						this.checkUpdates = false
					}
				})
			},
			
			// 更新操作
			systemUpdate(){
				this.updating = true
				this.serviceUpdateData.update_url = ''
				apiService.systemUpdate().then(res => {
					this.updating = false
					if (res.status == 1) {
						this.updateErorr = false
						this.updating = false
						this.updateSuccess = true
					}else{
						this.updateErorr = true
						this.updateErorrText = res.message
					}
				})
			}
		}
	}
</script>

<style>
</style>